<?php

/*
 * This file is part of Sulu.
 *
 * (c) Sulu GmbH
 *
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE.
 */

namespace Sulu\Bundle\CoreBundle\Tests\Unit\DependencyInjection;

use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase;
use Sulu\Bundle\CoreBundle\DependencyInjection\SuluCoreExtension;

class SuluCoreExtensionTest extends AbstractExtensionTestCase
{
    protected function setUp(): void
    {
        parent::setUp();

        $this->container->setParameter('kernel.bundles', []);
        $this->container->setParameter('kernel.project_dir', \dirname(__DIR__));
        $this->container->setParameter('kernel.cache_dir', \dirname(__DIR__) . '/var/cache');
        $this->container->setParameter('sulu.context', 'admin');
    }

    protected function getContainerExtensions(): array
    {
        return [
            new SuluCoreExtension(),
        ];
    }

    public function testLoadNoConfig(): void
    {
        $this->load([]);

        $this->assertEquals(
            ['de', 'en'],
            $this->container->getParameter('sulu_core.locales')
        );
        $this->assertEquals(
            ['en' => 'English', 'de' => 'Deutsch'],
            $this->container->getParameter('sulu_core.translated_locales')
        );
        $this->assertEquals(
            ['de', 'en'],
            $this->container->getParameter('sulu_core.translations')
        );
        $this->assertEquals(
            'en',
            $this->container->getParameter('sulu_core.fallback_locale')
        );
    }

    public function testLocales(): void
    {
        $this->load(
            [
                'locales' => ['en' => 'English', 'de' => 'Deutsch', 'fr' => 'France'],
                'translations' => ['de', 'en'],
                'fallback_locale' => 'en',
            ]
        );

        $this->assertEquals(
            ['en', 'de', 'fr'],
            $this->container->getParameter('sulu_core.locales')
        );
        $this->assertEquals(
            ['en' => 'English', 'de' => 'Deutsch', 'fr' => 'France'],
            $this->container->getParameter('sulu_core.translated_locales')
        );
        $this->assertEquals(
            ['de', 'en'],
            $this->container->getParameter('sulu_core.translations')
        );
        $this->assertEquals(
            'en',
            $this->container->getParameter('sulu_core.fallback_locale')
        );
    }
}
